<?php

ob_start();
include_once "header.php";
include_once "killclass.php";

$mail = $_GET['killid'];

$killMail = new Kill($mail);

if ($killMail->status == 0)
{
	echo ("<tr><th>Killmail not found</th></tr>");
}

else
{

	$shipValue = $killMail->shipValue;
	$modValue = $killMail->modValue;
	$totalValue = $shipValue + $modValue;
	
?>

<tr>
	<th>Details for <?php echo($killMail->victim);?>'s <?php echo($killMail->ship);?> loss</th>
</tr>
<tr>
	<td>
		<table style="width:100%">
			<tr>
				<td colspan="2">
				<div class="showKillDiv"><b>Financial Details</b></div>
				<div class="showKillDiv">
				<table style="text-align:left;" cellspacing="2">
					<tr>
						<td rowspan="2">
							<img src="images/money.png" />
						</td>
						<td><b>Total Value:</b> <?php echo(number_format($totalValue));?> ISK</td>
					</tr>
					<tr>
						<td><b>Ship:</b> <?php echo(number_format($shipValue));?> ISK - <b>Modules:</b> <?php echo(number_format($modValue));?> ISK</td>
					</tr>
				</table>
				</div>		
			</tr>
			<tr>
				<td colspan="2">			
		<?php
		
		$filename = "people/" . $killMail->victimID . ".png";
		
		if (!file_exists($filename))
		{
			$filename = "people/noImage.png";
		}	
		
		printf("
		<div class=\"showKillDiv\"><b>Victim Details (%s)</b></div>
		<div class=\"showKillDiv\">
		<table style=\"text-align:left;\" cellspacing=\"2\">
			<tr>
				<td rowspan=\"5\" style=\"text-align:left; width:140px; height:64px;\">
					<img alt=\"ship\" class=\"bigShipImage\" src=\"ships/%s.png\" />
					<img alt=\"player\" class=\"bigShipImage\" src=\"%s\" />
				</td>
				<td><b>Killed</b> %s</td>
			</tr>
			<tr>
				<td><b>Corp:</b> <a href=\"closses.php?id=%s\">%s</a></td>
			</tr>
			<tr>
				<td><b>Alliance:</b> <a href=\"alosses.php?id=%s\">%s</a></td>
			</tr>
			<tr>
				<td><b>Lost:</b> %s</td>
			</tr>
			<tr>
				<td><b>System:</b> %s (%s)</td>
			</tr>
		</table>
		</div>
		
		"
		,$killMail->victim, $killMail->shipGraphicID, $filename, date("l F jS Y",$killMail->timestamp), $killMail->corpID,
		$killMail->corp, $killMail->allianceID, $killMail->alliance, $killMail->ship, $killMail->solarSystem, $killMail->solarSystemSecurity);
		?>
				</td>
			</tr>
			<tr>
				<td style="width:50%; vertical-align:top;"><div class="showKillDiv"><b>Involved Parties</b></div>
				<?php
			
				foreach ($killMail->involvedParties as $involvedParty)
				{
	
					$filename = "ships/" . $involvedParty->shipGraphicID . ".png";
					
					if (!file_exists($filename))
					{
						$filename = "ships/noImage.png";
					}	
		
					// Laid the final blow?
					if ($involvedParty->finalBlow == 1)
					{
						$imageBorderColor = "FFCC00";
					}
					else
					{
						$imageBorderColor = "808080";
					}
					
					if (strlen($involvedParty->corp) > 22)
					{
						$corpName = substr($involvedParty->corp, 0, 22);
						$corpName = $corpName . "...";
					}
					else
					{
						$corpName = $involvedParty->corp;
					}
					
					if (strlen($involvedParty->alliance) > 22)
					{
						$allianceName = substr($involvedParty->alliance, 0, 22);
						$allianceName = $allianceName . "...";
					}
					else
					{
						$allianceName = $involvedParty->alliance;
					}

					if (strlen($involvedParty->weapon) > 22)
					{
						$killersWep = substr($involvedParty->weapon,0,22);
						$killersWep = $killersWep . "...";
					}
					else
					{
						$killersWep = $involvedParty->weapon;
					}
					
					printf("
					<div class=\"showKillDiv\">

					<table style=\"width:100%%;\" cellspacing=\"2\" >
						<tr>
							<td rowspan=\"5\" style=\"text-align:center; width:64px; height:64px;\">
								<img alt=\"Ship Image\" style=\"border:0; width:64px; height:64px; border:1px solid #%s;\" src=\"%s\" />
							</td>
							<td>Name: <a href=\"pkills.php?id=%s\">%s</a></td>
						</tr>
						<tr>
							<td>Corp: <a href=\"ckills.php?id=%s\">%s</a></td>
						</tr>
						<tr>
							<td>Alliance: <a href=\"akills.php?id=%s\">%s</a></td>
						</tr>
						<tr>
							<td>Ship: %s</td>
						</tr>
						<tr>
							<td>Weapon: %s</td>
						</tr>
					</table>
					</div>"
					,$imageBorderColor, $filename, $involvedParty->playerID, $involvedParty->player, $involvedParty->corpID, $corpName, $involvedParty->allianceID, $allianceName, $involvedParty->ship, $killersWep);
				}
				?>
				</td>
				<td style="width:50%; vertical-align:top;">
					<div class="showKillDiv"><b>Destroyed Equipment</b></div>
					<table>
					<?php
									
					echo ("<tr><td><table>");
					
					foreach ($killMail->destroyedItems as $destroyedItem)
					{
						if ($destroyedItem->location == 1)
						{
							printf ("<tr><td style=\"width:32px;\"><img class=\"tableborder\" src=\"items/%s\" alt=\"item\" style=\"width:32px\" /></td><td style=\"width:200px;\">%s</td><td style=\"width:48px;\">%s</td></tr>",
							$destroyedItem->itemGraphic, $destroyedItem->itemName, $destroyedItem->quant);
						}
					}
					
					echo ("</table></td></tr>");
					
					?>
					</table>
					</div>
					<div class="showKillDiv"><b>Destroyed Cargo</b></div>
					<table>
					<?php
					
					echo ("<tr><td><table>");
					
					foreach ($killMail->destroyedItems as $destroyedItem)
					{
						if ($destroyedItem->location == 2)
						{
							printf ("<tr><td style=\"width:32px;\"><img class=\"tableborder\" src=\"items/%s\" alt=\"item\" style=\"width:32px\" /></td><td style=\"width:200px;\">%s</td><td style=\"width:48px;\">%s</td></tr>",
							$destroyedItem->itemGraphic, $destroyedItem->itemName, $destroyedItem->quant);
						}
					}
					
					echo ("</table></td></tr>");
					
					?>
					</table>
					</div>
					<div class="showKillDiv"><b>Destroyed Drones</b></div>
					<table>
					<?php
					
					echo ("<tr><td><table>");
					
					foreach ($killMail->destroyedItems as $destroyedItem)
					{
						if ($destroyedItem->location == 3)
						{
							printf ("<tr><td style=\"width:32px;\"><img class=\"tableborder\" src=\"items/%s\" alt=\"item\" style=\"width:32px\" /></td><td style=\"width:200px;\">%s</td><td style=\"width:48px;\">%s</td></tr>",
							$destroyedItem->itemGraphic, $destroyedItem->itemName, $destroyedItem->quant);
						}
					}
					
					echo ("</table></td></tr>");
					
					?>
					</table>
				</td>
			</tr>
		</table>
	</td>
</tr>

<?php
}

require "footer.php";
ob_flush();

?>